package com.keffect.effects.animatedEffects;

import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.Rectangle;

import com.keffect.effects.AnimatedEffect;


public class Shape extends AnimatedEffect{
	private Rectangle r;
	public Shape(long duration) {
		super(duration);
	}

	@Override
	public void initEffectProperties() {
		int width=getEffectPanel().getWidth()/2;
		int height=getEffectPanel().getHeight()/2;
		r=new Rectangle(width, height,0,0);
		
		long frames = width >= height ? width : height;
		setFrames(frames);
	}

	@Override
	public void doPaintBefore(Graphics2D g) {
		g.setClip(r);
	}

	@Override
	public void doPaintAfter(Graphics2D g) {
		g.setStroke(new BasicStroke(10.0f));
		g.drawRect((int)r.getX(), (int)r.getY(), (int)r.getWidth()-1,(int)r.getHeight()-1);
	}

	@Override
	public void run() {
		r.grow(1, 1);
	}

	@Override
	public boolean isRunning() {
		return r.getHeight()<getEffectPanel().getHeight() || 
				r.getWidth()<getEffectPanel().getWidth();
	}

}
